#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time    : 2018/5/18 0018 上午 11:23
# @Author  : Jython <ijython@qq.com>
# @File    : functions.py

from flask import jsonify
class Gview(object):
	"""
	api对外暴露统一的接口
	"""
	@classmethod
	def __init__( self ):
		pass
	@staticmethod
	def Vsuccess( data=None, message='success' ):
		"""
		返回成功调用方法
		:param data:
		:param message:
		:return:
		"""
		obj = {}
		obj[ 'data' ] = data
		obj[ 'code' ] = 200
		obj[ 'message' ] = message
		return obj
	@staticmethod
	def Vfail( message, code=500, data=None ):
		"""
		返回失败调用方法
		:param message:
		:param error:
		:param data:
		:return:
		"""
		obj = {}
		obj[ 'data' ] = data
		obj[ 'code' ] = code
		obj[ 'message' ] = message
		return jsonify(obj)
	@staticmethod
	def Vreturn( fn ):
		"""
		统一成返回api的装饰器
		:param fn:
		:return:
		"""
		def decorator( *args, **kwargs ):
			res = fn(*args, **kwargs)
			return jsonify(res)
